package org.bcos.contract.source;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;
import org.bcos.channel.client.TransactionSucCallback;
import org.bcos.web3j.abi.EventEncoder;
import org.bcos.web3j.abi.EventValues;
import org.bcos.web3j.abi.TypeReference;
import org.bcos.web3j.abi.datatypes.Address;
import org.bcos.web3j.abi.datatypes.Event;
import org.bcos.web3j.abi.datatypes.Function;
import org.bcos.web3j.abi.datatypes.Type;
import org.bcos.web3j.abi.datatypes.Utf8String;
import org.bcos.web3j.abi.datatypes.generated.Uint256;
import org.bcos.web3j.crypto.Credentials;
import org.bcos.web3j.crypto.EncryptType;
import org.bcos.web3j.protocol.Web3j;
import org.bcos.web3j.protocol.core.DefaultBlockParameter;
import org.bcos.web3j.protocol.core.methods.request.EthFilter;
import org.bcos.web3j.protocol.core.methods.response.Log;
import org.bcos.web3j.protocol.core.methods.response.TransactionReceipt;
import org.bcos.web3j.tx.Contract;
import org.bcos.web3j.tx.TransactionManager;
import rx.Observable;
import rx.functions.Func1;

/**
 * Auto generated code.<br>
 * <strong>Do not modify!</strong><br>
 * Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>, or {@link org.bcos.web3j.codegen.SolidityFunctionWrapperGenerator} to update.
 *
 * <p>Generated with web3j version none.
 */
public final class ConfigAction extends Contract {
    private static String BINARY = "6060604052341561000c57fe5b5b5b5b6107f28061001e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063693ec85e14610051578063e942b51614610139578063ff68fa6e146101d6575bfe5b341561005957fe5b6100a9600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190505061027d565b60405180806020018381526020018281038252848181518152602001915080519060200190808383600083146100fe575b8051825260208311156100fe576020820191506020810190506020830392506100da565b505050905090810190601f16801561012a5780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b341561014157fe5b6101d4600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610406565b005b34156101de57fe5b6101f460048080359060200190919050506105b0565b6040518080602001828103825283818151815260200191508051906020019080838360008314610243575b8051825260208311156102435760208201915060208101905060208303925061021f565b505050905090810190601f16801561026f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61028561066d565b60006001836040518082805190602001908083835b602083106102bd578051825260208201915060208101905060208303925061029a565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206000016001846040518082805190602001908083835b602083106103295780518252602082019150602081019050602083039250610306565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060010154818054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103f55780601f106103ca576101008083540402835291602001916103f5565b820191906000526020600020905b8154815290600101906020018083116103d857829003601f168201915b50505050509150915091505b915091565b60006001836040518082805190602001908083835b6020831061043e578051825260208201915060208101905060208303925061041b565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206001015414156104b9576000805480600101828161048f9190610681565b916000526020600020900160005b84909190915090805190602001906104b69291906106ad565b50505b806001836040518082805190602001908083835b602083106104f057805182526020820191506020810190506020830392506104cd565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060000190805190602001906105399291906106ad565b50436001836040518082805190602001908083835b60208310610571578051825260208201915060208101905060208303925061054e565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600101819055505b5050565b6000818154811015156105bf57fe5b906000526020600020900160005b915090508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106655780601f1061063a57610100808354040283529160200191610665565b820191906000526020600020905b81548152906001019060200180831161064857829003601f168201915b505050505081565b602060405190810160405280600081525090565b8154818355818115116106a8578183600052602060002091820191016106a7919061072d565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106106ee57805160ff191683800117855561071c565b8280016001018555821561071c579182015b8281111561071b578251825591602001919060010190610700565b5b5090506107299190610759565b5090565b61075691905b808211156107525760008181610749919061077e565b50600101610733565b5090565b90565b61077b91905b8082111561077757600081600090555060010161075f565b5090565b90565b50805460018160011615610100020316600290046000825580601f106107a457506107c3565b601f0160209004906000526020600020908101906107c29190610759565b5b505600a165627a7a72305820b50ff54f1c6f28b75bf9956430fb937435e8dbab37061128c65aaa36226eb2d20029";

    public static final String ABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"key\",\"type\":\"string\"}],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"key\",\"type\":\"string\"},{\"name\":\"value\",\"type\":\"string\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"allItems\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"code\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"msg\",\"type\":\"string\"}],\"name\":\"LogMessage\",\"type\":\"event\"}]";

    private static String GUOMI_BINARY = "6060604052341561000c57fe5b5b5b5b6107f28061001e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630b7ec902146100515780631a391cb4146100f85780637b1b8e0314610195575bfe5b341561005957fe5b61006f600480803590602001909190505061027d565b60405180806020018281038252838181518152602001915080519060200190808383600083146100be575b8051825260208311156100be5760208201915060208101905060208303925061009a565b505050905090810190601f1680156100ea5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561010057fe5b610193600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190505061033a565b005b341561019d57fe5b6101ed600480803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919050506104e4565b6040518080602001838152602001828103825284818151815260200191508051906020019080838360008314610242575b8051825260208311156102425760208201915060208101905060208303925061021e565b505050905090810190601f16801561026e5780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b60008181548110151561028c57fe5b906000526020600020900160005b915090508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103325780601f1061030757610100808354040283529160200191610332565b820191906000526020600020905b81548152906001019060200180831161031557829003601f168201915b505050505081565b60006001836040518082805190602001908083835b60208310610372578051825260208201915060208101905060208303925061034f565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206001015414156103ed57600080548060010182816103c3919061066d565b916000526020600020900160005b84909190915090805190602001906103ea929190610699565b50505b806001836040518082805190602001908083835b602083106104245780518252602082019150602081019050602083039250610401565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600001908051906020019061046d929190610699565b50436001836040518082805190602001908083835b602083106104a55780518252602082019150602081019050602083039250610482565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600101819055505b5050565b6104ec610719565b60006001836040518082805190602001908083835b602083106105245780518252602082019150602081019050602083039250610501565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206000016001846040518082805190602001908083835b60208310610590578051825260208201915060208101905060208303925061056d565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060010154818054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561065c5780601f106106315761010080835404028352916020019161065c565b820191906000526020600020905b81548152906001019060200180831161063f57829003601f168201915b50505050509150915091505b915091565b81548183558181151161069457818360005260206000209182019101610693919061072d565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106106da57805160ff1916838001178555610708565b82800160010185558215610708579182015b828111156107075782518255916020019190600101906106ec565b5b5090506107159190610759565b5090565b602060405190810160405280600081525090565b61075691905b808211156107525760008181610749919061077e565b50600101610733565b5090565b90565b61077b91905b8082111561077757600081600090555060010161075f565b5090565b90565b50805460018160011615610100020316600290046000825580601f106107a457506107c3565b601f0160209004906000526020600020908101906107c29190610759565b5b505600a165627a7a72305820290a425897e166840ed7986b1931e3c57a2ab29775cc3b4e5f5c5d054f3698db0029";

    private ConfigAction(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, Boolean isInitByName) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit, isInitByName);
        if(EncryptType.encryptType == 1) super.setContractBinary(GUOMI_BINARY);
    }

    private ConfigAction(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, Boolean isInitByName) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit, isInitByName);
        if(EncryptType.encryptType == 1) super.setContractBinary(GUOMI_BINARY);
    }

    private ConfigAction(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit, false);
        if(EncryptType.encryptType == 1) super.setContractBinary(GUOMI_BINARY);
    }

    private ConfigAction(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit, false);
        if(EncryptType.encryptType == 1) super.setContractBinary(GUOMI_BINARY);
    }

    public static List<LogMessageEventResponse> getLogMessageEvents(TransactionReceipt transactionReceipt) {
        final Event event = new Event("LogMessage", 
                Arrays.<TypeReference<?>>asList(),
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}));
        List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
        ArrayList<LogMessageEventResponse> responses = new ArrayList<LogMessageEventResponse>(valueList.size());
        for (EventValues eventValues : valueList) {
            LogMessageEventResponse typedResponse = new LogMessageEventResponse();
            typedResponse.addr = (Address) eventValues.getNonIndexedValues().get(0);
            typedResponse.code = (Uint256) eventValues.getNonIndexedValues().get(1);
            typedResponse.msg = (Utf8String) eventValues.getNonIndexedValues().get(2);
            responses.add(typedResponse);
        }
        return responses;
    }

    public Observable<LogMessageEventResponse> logMessageEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        final Event event = new Event("LogMessage", 
                Arrays.<TypeReference<?>>asList(),
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}));
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(event));
        return web3j.ethLogObservable(filter).map(new Func1<Log, LogMessageEventResponse>() {
            @Override
            public LogMessageEventResponse call(Log log) {
                EventValues eventValues = extractEventParameters(event, log);
                LogMessageEventResponse typedResponse = new LogMessageEventResponse();
                typedResponse.addr = (Address) eventValues.getNonIndexedValues().get(0);
                typedResponse.code = (Uint256) eventValues.getNonIndexedValues().get(1);
                typedResponse.msg = (Utf8String) eventValues.getNonIndexedValues().get(2);
                return typedResponse;
            }
        });
    }

    public Future<List<Type>> get(Utf8String key) {
        Function function = new Function("get", 
                Arrays.<Type>asList(key), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Uint256>() {}));
        return executeCallMultipleValueReturnAsync(function);
    }

    public Future<TransactionReceipt> set(Utf8String key, Utf8String value) {
        Function function = new Function("set", Arrays.<Type>asList(key, value), Collections.<TypeReference<?>>emptyList());
        return executeTransactionAsync(function);
    }

    public void set(Utf8String key, Utf8String value, TransactionSucCallback callback) {
        Function function = new Function("set", Arrays.<Type>asList(key, value), Collections.<TypeReference<?>>emptyList());
        executeTransactionAsync(function, callback);
    }

    public Future<Utf8String> allItems(Uint256 param0) {
        Function function = new Function("allItems", 
                Arrays.<Type>asList(param0), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
        return executeCallSingleValueReturnAsync(function);
    }

    public static Future<ConfigAction> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
        if(EncryptType.encryptType == 1) setBinary(getGuomiBinary());
        return deployAsync(ConfigAction.class, web3j, credentials, gasPrice, gasLimit, BINARY, "", initialWeiValue);
    }

    public static Future<ConfigAction> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
        if(EncryptType.encryptType == 1) setBinary(getGuomiBinary());
        return deployAsync(ConfigAction.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "", initialWeiValue);
    }

    public static ConfigAction load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new ConfigAction(contractAddress, web3j, credentials, gasPrice, gasLimit, false);
    }

    public static ConfigAction load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new ConfigAction(contractAddress, web3j, transactionManager, gasPrice, gasLimit, false);
    }

    public static ConfigAction loadByName(String contractName, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new ConfigAction(contractName, web3j, credentials, gasPrice, gasLimit, true);
    }

    public static ConfigAction loadByName(String contractName, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new ConfigAction(contractName, web3j, transactionManager, gasPrice, gasLimit, true);
    }

    public static void setBinary(String binary) {
        BINARY = binary;
    }

    public static String getGuomiBinary() {
        return GUOMI_BINARY;
    }

    public static class LogMessageEventResponse {
        public Address addr;

        public Uint256 code;

        public Utf8String msg;
    }
}
